<!-- NProgress -->
<link href="/vendors/nprogress/nprogress.css" rel="stylesheet" />
<!-- 上传图片 -->
<link href="/vendors/fileinput/fileinput.min.css" rel="stylesheet" />

<div id="profileDiv" class="right_col" role="main">
    <div class="">
        <div class="page-title">
            <div class="title_left">
                <h3>User Profile</h3>
            </div>
        </div>

        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>User Report <small>Activity report</small></h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li>
                                <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                            <li class="dropdown">
                                <a
                                        href="#"
                                        class="dropdown-toggle"
                                        data-toggle="dropdown"
                                        role="button"
                                        aria-expanded="false"
                                ><i class="fa fa-wrench"></i
                                ></a>
                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                    <a class="dropdown-item" href="#">Settings 1</a>
                                    <a class="dropdown-item" href="#">Settings 2</a>
                                </div>
                            </li>
                            <li>
                                <a class="close-link"><i class="fa fa-close"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <div class="col-md-3 col-sm-3 profile_left">
                            <div class="profile_img">
                                <div id="crop-avatar">
                                    <!-- Current avatar -->
                                    <img
                                            class="img-responsive avatar-view"
                                            :src="user.userImage"
                                            alt="Avatar"
                                            title="Change the avatar"
                                    />
                                </div>
                            </div>
                            <h3>{{user.userName}}</h3>

                            <ul class="list-unstyled user_data">
                                <li>
                                    <i class="fa fa-map-marker user-profile-icon"></i> San Francisco, California, USA
                                </li>

                                <li><i class="fa fa-briefcase user-profile-icon"></i> Software Engineer</li>

                                <li class="m-top-xs">
                                    <i class="fa fa-external-link user-profile-icon"></i>
                                    <a href="http://www.kimlabs.com/profile/" target="_blank">www.kimlabs.com</a>
                                </li>
                            </ul>

                            <a data-toggle="modal" data-target="#profileEdit" class="btn btn-success"
                            ><i class="fa fa-edit m-right-xs"></i>Edit Profile</a
                            >
                            <br />

                            <!-- start skills -->
                            <h4>Skills</h4>
                            <ul class="list-unstyled user_data">
                                <li>
                                    <p>Web Applications</p>
                                    <div class="progress progress_sm">
                                        <div
                                                class="progress-bar bg-green"
                                                role="progressbar"
                                                data-transitiongoal="50"
                                        ></div>
                                    </div>
                                </li>
                                <li>
                                    <p>Website Design</p>
                                    <div class="progress progress_sm">
                                        <div
                                                class="progress-bar bg-green"
                                                role="progressbar"
                                                data-transitiongoal="70"
                                        ></div>
                                    </div>
                                </li>
                            </ul>
                            <!-- end of skills -->
                        </div>
                        <div class="col-md-9 col-sm-9">
                            <div class="profile_title">
                                <div class="col-md-6">
                                    <h2>User Activity Report</h2>
                                </div>
                                <div class="col-md-6">
                                    <div
                                            id="reportrange"
                                            class="pull-right"
                                            style="
											margin-top: 5px;
											background: #fff;
											cursor: pointer;
											padding: 5px 10px;
											border: 1px solid #e6e9ed;
										"
                                    >
                                        <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
                                        <span>December 30, 2014 - January 28, 2015</span> <b class="caret"></b>
                                    </div>
                                </div>
                            </div>
                            <!-- start of user-activity-graph -->
                            <div id="graph_bar" style="width: 100%; height: 280px"></div>
                            <!-- end of user-activity-graph -->

                            <div class="" role="tabpanel" data-example-id="togglable-tabs">
                                <ul id="myTab" class="nav nav-tabs bar_tabs" role="tablist">
                                    <li role="presentation" class="active">
                                        <a
                                                href="#tab_content1"
                                                id="home-tab"
                                                role="tab"
                                                data-toggle="tab"
                                                aria-expanded="true"
                                        >Recent Activity</a
                                        >
                                    </li>
                                    <li role="presentation" class="">
                                        <a
                                                href="#tab_content2"
                                                role="tab"
                                                id="profile-tab"
                                                data-toggle="tab"
                                                aria-expanded="false"
                                        >Projects Worked on</a
                                        >
                                    </li>
                                    <li role="presentation" class="">
                                        <a
                                                href="#tab_content3"
                                                role="tab"
                                                id="profile-tab2"
                                                data-toggle="tab"
                                                aria-expanded="false"
                                        >Profile</a
                                        >
                                    </li>
                                </ul>
                                <div id="myTabContent" class="tab-content">
                                    <div
                                            role="tabpanel"
                                            class="tab-pane active"
                                            id="tab_content1"
                                            aria-labelledby="home-tab"
                                    >
                                        <!-- start recent activity -->
                                        <ul class="messages">
                                            <li>
                                                <img src="/images/img.jpg" class="avatar" alt="Avatar" />
                                                <div class="message_date">
                                                    <h3 class="date text-info">24</h3>
                                                    <p class="month">May</p>
                                                </div>
                                                <div class="message_wrapper">
                                                    <h4 class="heading">Desmond Davison</h4>
                                                    <blockquote class="message">
                                                        Raw denim you probably haven't heard of them jean shorts Austin.
                                                        Nesciunt tofu stumptown aliqua butcher retro keffiyeh
                                                        dreamcatcher synth.
                                                    </blockquote>
                                                    <br />
                                                    <p class="url">
														<span
                                                                class="fs1 text-info"
                                                                aria-hidden="true"
                                                                data-icon=""
                                                        ></span>
                                                        <a href="#"
                                                        ><i class="fa fa-paperclip"></i> User Acceptance Test.doc
                                                        </a>
                                                    </p>
                                                </div>
                                            </li>
                                        </ul>
                                        <!-- end recent activity -->
                                    </div>
                                    <div
                                            role="tabpanel"
                                            class="tab-pane fade"
                                            id="tab_content2"
                                            aria-labelledby="profile-tab"
                                    >
                                        <!-- start user projects -->
                                        <table class="data table table-striped no-margin">
                                            <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Project Name</th>
                                                <th>Client Company</th>
                                                <th class="hidden-phone">Hours Spent</th>
                                                <th>Contribution</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr>
                                                <td>1</td>
                                                <td>New Company Takeover Review</td>
                                                <td>Deveint Inc</td>
                                                <td class="hidden-phone">18</td>
                                                <td class="vertical-align-mid">
                                                    <div class="progress">
                                                        <div
                                                                class="progress-bar progress-bar-success"
                                                                data-transitiongoal="35"
                                                        ></div>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>2</td>
                                                <td>New Partner Contracts Consultanci</td>
                                                <td>Deveint Inc</td>
                                                <td class="hidden-phone">13</td>
                                                <td class="vertical-align-mid">
                                                    <div class="progress">
                                                        <div
                                                                class="progress-bar progress-bar-danger"
                                                                data-transitiongoal="15"
                                                        ></div>
                                                    </div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        <!-- end user projects -->
                                    </div>
                                    <div
                                            role="tabpanel"
                                            class="tab-pane fade"
                                            id="tab_content3"
                                            aria-labelledby="profile-tab"
                                    >
                                        <p>
                                            xxFood truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin
                                            coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next
                                            level wes anderson artisan four loko farm-to-table craft beer twee. Qui
                                            photo booth letterpress, commodo enim craft beer mlkshk
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 引入模态框 -->
    <div th:replace="account/profileEdit"></div>
</div>

<!-- NProgress -->
<script src="/vendors/nprogress/nprogress.js"></script>
<!-- morris.js -->
<script src="/vendors/raphael/raphael.min.js"></script>
<script src="/vendors/morris.js/morris.min.js"></script>
<!-- bootstrap-progressbar -->
<script src="/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
<!-- 上传图片 -->
<script src="/vendors/fileinput/fileinput.min.js" type="text/javascript"></script>

<script>
    var profileVue = new Vue({
        el: "#profileDiv",
        data: {
            user: {
                id:"",
                userName: "",
                email: "",
                userImage: "",
            },
            imageTypes: [],
            imageType: {
                name: "big-image",
                length: 220,
                width: 220,
                size: 200
            },
        },
        methods: {
            initImageType: function () {
                var self = this;
                $.ajax({
                    url: "/api/dictionary/imageType",
                    type: "get",
                    success: function (rs) {
                        self.imageTypes = rs;
                    },
                    error: function (data) {
                        layer.alert(data.responseText, { icon: 0 });
                    },
                });
            },
            initUser: function () {
                var self = this;
                var userId = $("#userId").val();
                $.ajax({
                    url: "/api/user/" + userId,
                    type: "get",
                    success: function (rs) {
                        self.user = rs;
                    },
                    error: function (data) {
                        layer.alert(data.responseText, { icon: 0 });
                    },
                });
            },
            initFileInput: function() {
                var self = this;
                $("[name='image']").fileinput({
                    uploadUrl: "/api/image/" + self.imageType.name,
                    enctype: 'multipart/form-data',
                    previewFileType: "image",
                    uploadAsync: true,
                    allowedFileExtensions: ["png", "jpg", "jpeg", "ico", "bmp", "gif"],
                    maxFileCount: 1,
                    maxFileSize: self.imageType.size,
                    minImageWidth: 5,
                    minImageHeight: 5,
                    maxImageWidth: self.imageType.width,
                    maxImageHeight: self.imageType.length,
                    msgFilesTooMany: "Upload file count({n} - {m})",
                    showCaption: false,
                    dropZoneEnabled:false,
                    showBrowse: true,
                    browseClass: "btn btn-primary",
                    uploadClass: "btn btn-info",
                    removeClass: "btn btn-danger"
                }).on('fileerror', function (event, data, msg) {
                    layer.alert("Upload file failed." + msg, {icon: 0});
                }).on('fileuploaded', function (event, data) {
                    if (data.response.status == 200) {
                        self.user.userImage = data.response.data;
                        $("[name='image']").fileinput('disable');
                    } else {
                        $(".fileinput-remove-button").click();
                    }
                    layer.alert(data.response.message, {icon: 0});
                }).on('fileclear', function (event) {
                });
            },
            refreshFileInput: function() {
                this.imageType.name = $("[name='imageTypes']").find("option:selected").val();
                this.imageType.length = $("[name='imageTypes']").find("option:selected").attr("length");
                this.imageType.width = $("[name='imageTypes']").find("option:selected").attr("width");
                this.imageType.size = $("[name='imageTypes']").find("option:selected").attr("size");
                $("[name='image']").fileinput('refresh',{
                    maxFileSize:this.imageType.size,
                    maxImageWidth:this.imageType.width,
                    maxImageHeight:this.imageType.length
                });
            },
            updateUser: function() {
                // 判断 user 属性

                var self = this;
                $.ajax({
                    url: "/api/user",
                    type: "put",
                    contentType: "application/json",
                    data: JSON.stringify(self.user),
                    success: function (data) {
                        if (data.status == 200) {
                            $("#profileEdit").modal("hide");
                            layer.msg(data.message, { icon: 0 });
                        } else {
                            layer.msg(data.message, { icon: 0 });
                        }
                    },
                    error: function (data) {
                        layer.msg(data.responseText, { icon: 0 });
                    },
                });
            }
        },
        mounted: function () {
            this.initUser();
            this.initImageType();
            this.initFileInput();
        },
    });
</script>
